import CURDHelper from '@/utils/CURDHelper'
import PageConfig from '@/utils/pageConfig'
import { getBtnCtr } from '@/utils/BtnControl'
import Query from '@/components/Query';
import XEUtils from 'xe-utils';
export default {
  name: 'CustomerResume',
  components: {
    Query
  },
  data() {
    return {
      QueryParams: {
        CustomerName: undefined
      },
      componentSize: PageConfig.ComponentSize,
      duration: PageConfig.Duration,
      btnPromission: '',
      editModal: false,
      QueryConditions: [],
      BaseApiUrl: '/api/Xmjckhxx',
      XmxxApiUrl: '/api/Xmglxmxx',
      XmxxpcApiUrl: '/api/Xmglxmxxpc',
      XmxxlcApiUrl: '/api/Xmglxmxxlc',
      XmxxskApiUrl: '/api/Xmglxmxxsk',
      XmxxkpApiUrl: '/api/Xmglxmxxkp',
      KhgdglApiUrl: '/api/Xmkhgdgl',
      KhgltxApiUrl: '/api/Xmkhgltx',
      selectTab: 'tab1',
      childSelectTab: 'childtab1',
      CustomSelectedRow: undefined,
      ProjectSelectdRow: undefined,

      LeftGridOptions: {
        id: 'BaseCustoemr_MainGrid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 750,
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        checkboxConfig: {
          highlight: true,
          range: true
        },
        columns: [
          { field: 'khmc', title: '客户名称', width: 248, showOverflow: true }
        ],
        data: []
      },
      Tab1TopGridOptions: {
        id: 'CustomerResume_Tab1TopGrid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 350,
        columnConfig: {
          resizable: true
        },
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        checkboxConfig: {
          highlight: true,
          range: true
        },
        exportConfig: {
        },
        customConfig: {
          mode: 'drawer',
          storage: true
        },
        columns: [
          { type: 'seq', width: 50 },
          { field: 'txid', title: '体系ID', visible: false },
          { field: 'khmc', title: '客户名称', sortable: true, minWidth: 120, showOverflow: true },
          { field: 'txmc', title: '体系名称', sortable: true, minWidth: 120, showOverflow: true },
          { field: 'txgg', title: '体系规格', minWidth: 100, showOverflow: true },
          { field: 'rzbz', title: '认证标准', minWidth: 120, showOverflow: true },
          { field: 'erpbh', title: 'ERP编号', minWidth: 100, showOverflow: true },
          { field: 'sxq', title: '市县区', minWidth: 120, showOverflow: true },
          { field: 'shlx', title: '审核类型', minWidth: 100, showOverflow: true },
          { field: 'rzfw', title: '认证范围', minWidth: 100, showOverflow: true },
          { field: 'txrs', title: '体系人数', minWidth: 80, showOverflow: true },
          { field: 'csje', title: '初审金额', minWidth: 80, showOverflow: true },
          { field: 'jsje', title: '监审金额', minWidth: 80, showOverflow: true },
          {
            field: 'htqdrq', title: '签单日期', sortable: true, minWidth: 120, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
          { field: 'shzt', title: '审核状态', minWidth: 80, showOverflow: true, slots: { default: 'auditStatus' } },
          { field: 'shr', title: '审核人', minWidth: 80, showOverflow: true },
          { field: 'shsj', title: '审核时间', minWidth: 120, showOverflow: true },
          { field: 'createtime', title: '创建时间', width: 120, showOverflow: true },
          { field: 'createname', title: '创建人', width: 60, showOverflow: true },
          { field: 'updatetime', title: '更新时间', width: 150, showOverflow: true },
          { field: 'updatename', title: '更新人', width: 60, showOverflow: true },

        ],
        data: []
      },
      Tab2TopGridOptions: {
        id: 'CustomerResume_Tab2TopGrid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 750,
        columnConfig: {
          resizable: true
        },
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        exportConfig: {
        },
        customConfig: {
          mode: 'drawer',
          storage: true
        },
        columns: [
          { type: 'seq', width: 50 },
          { field: 'gdr', title: '跟单人', sortable: true, width: 100, showOverflow: true },
          {
            field: 'gjsj', title: '跟进日期', sortable: true, width: 120, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
          { field: 'txmc', title: '跟进体系', minWidth: 120, showOverflow: true },
          { field: 'gdxq', title: '详情', minWidth: 500, showOverflow: true },
          {
            field: 'xcgjsj', title: '下次跟进日期', width: 120, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
        ],
        data: []
      },
      Tab3TopGridOptions: {
        id: 'CustomerResume_Tab3TopGrid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 750,
        columnConfig: {
          resizable: true
        },
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        customConfig: {
          mode: 'drawer',
          storage: true
        },
        columns: [
          { type: 'seq', width: 50 },
          { field: 'txmc', title: '体系名称', minWidth: 150, showOverflow: true },
          { field: 'txgg', title: '体系规格', minWidth: 120, showOverflow: true },
          { field: 'rzbz', title: '认证标准', minWidth: 120, showOverflow: true },
          { field: 'zsh', title: '证书号', minWidth: 120, showOverflow: true },
          { field: 'zslb', title: '证书类别', minWidth: 120, showOverflow: true },
          {
            field: 'zsrq', title: '证书日期', minWidth: 120, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
          {
            field: 'zsyxq', title: '证书有效期', minWidth: 120, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
          { field: 'zsjg', title: '证书机构', minWidth: 120, showOverflow: true },
          {
            field: 'mcshrq', title: '末次审核日期', minWidth: 150, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
          {
            field: 'xcshrq', title: '下次审核日期', minWidth: 150, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
        ],
        data: []
      },
      Tab1ChildTab1GridOptions: {
        id: 'CustomerResume_Tab1ChildTab1Grid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 350,
        columnConfig: {
          resizable: true
        },
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        checkboxConfig: {
          highlight: true,
          range: true
        },
        exportConfig: {
        },
        customConfig: {
          mode: 'drawer',
          storage: true
        },
        columns: [
          { type: 'seq', width: 50 },
          { field: 'txid', title: '体系ID', visible: false },
          { field: 'lcmc', title: '流程名称', sortable: true, minWidth: 120, showOverflow: true },
          {
            field: 'kssj', title: '审核开始日期', sortable: true, minWidth: 120, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
          {
            field: 'jssj', title: '审核结束日期', sortable: true, minWidth: 120, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
          { field: 'shy', title: '审核员', minWidth: 80, showOverflow: true },
          { field: 'rt', title: '人天数', minWidth: 80, showOverflow: true },

        ],
        data: []
      },
      Tab1ChildTab2GridOptions: {
        id: 'CustomerResume_Tab1ChildTab2Grid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 350,
        columnConfig: {
          resizable: true
        },
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        checkboxConfig: {
          highlight: true,
          range: true
        },
        exportConfig: {
        },
        customConfig: {
          mode: 'drawer',
          storage: true
        },
        columns: [
          { type: 'seq', width: 50 },
          { field: 'lcmc', title: '流程名称', sortable: true, minWidth: 120, showOverflow: true },
          {
            field: 'ksrq', title: '审核开始日期', sortable: true, minWidth: 120, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
          {
            field: 'jsrq', title: '审核结束日期', sortable: true, minWidth: 120, showOverflow: true,
            formatter: ({ cellValue }) => XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
          },
          { field: 'shy', title: '审核员', minWidth: 80, showOverflow: true },
          { field: 'shrt', title: '人天数', minWidth: 80, showOverflow: true },
          { field: 'khyq', title: '客户要求', minWidth: 200, showOverflow: true },
          { field: 'bz', title: '备注', minWidth: 80, showOverflow: true },
          { field: 'lczt', title: '流程状态', minWidth: 80, showOverflow: true, slots: { default: 'status' } },
          { field: 'lcqrr', title: '确认人', minWidth: 80, showOverflow: true },
          { field: 'lcqrsj', title: '确认时间', minWidth: 120, showOverflow: true },

        ],
        data: []
      },
      Tab1ChildTab3GridOptions: {
        id: 'CustomerResume_Tab1ChildTab3Grid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 350,
        columnConfig: {
          resizable: true
        },
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        customConfig: {
          mode: 'drawer',
          storage: true
        },
        columns: [
          { type: 'seq', width: 50 },
          { field: 'skxm', title: '收款项', minWidth: 200, showOverflow: true, },
          { field: 'ysrq', title: '应收日期', minWidth: 120, showOverflow: true, },
          { field: 'skje', title: '应收金额', minWidth: 90, showOverflow: true, },
          { field: 'skzt', title: '收款状态', minWidth: 90, showOverflow: true, slots: { default: 'receiveStatus' } },
          { field: 'ssje', title: '实收金额', minWidth: 90, showOverflow: true, },
          { field: 'skr', title: '收款人', minWidth: 80, showOverflow: true, },
          { field: 'skrq', title: '收款日期', minWidth: 150, showOverflow: true, },
        ],
        data: []
      },
      Tab1ChildTab4GridOptions: {
        id: 'CustomerResume_Tab1ChildTab4Grid',
        border: true,
        stripe: true,
        loading: false,
        size: PageConfig.ComponentSize,
        height: 350,
        columnConfig: {
          resizable: true
        },
        rowConfig: {
          isHover: true,
          isCurrent: true
        },
        customConfig: {
          mode: 'drawer',
          storage: true
        },
        columns: [
          { type: 'seq', width: 50 },
          { field: 'kpxm', title: '开票项', minWidth: 200, showOverflow: true, },
          { field: 'kpje', title: '应开金额', minWidth: 90, showOverflow: true, },
          { field: 'kpzt', title: '开票状态', minWidth: 90, showOverflow: true, slots: { default: 'invoiceStatus' } },
          { field: 'skje', title: '实开金额', minWidth: 90, showOverflow: true, },
          { field: 'fph', title: '发票号', minWidth: 120, showOverflow: true, },
          { field: 'kpr', title: '开票人', minWidth: 80, showOverflow: true, },
          { field: 'kprq', title: '开票日期', minWidth: 120, showOverflow: true, }
        ],
        data: []
      },
    }
  },
  created() {
    // 动态头部按钮
    this.btnPromission = getBtnCtr(
      this.$route.path,
      this.$store.getters.userPermission
    )
  },
  methods: {
    handleQuery() {
      this.QueryConditions = [];
      if (this.QueryParams.CustomerName) {
        this.QueryConditions.push({
          column: 'khmc',
          condition: '6',
          content: this.QueryParams.CustomerName
        })
      }
      this.DoQuery(this.QueryConditions);
    },
    handleLeftGridCellClick({ row }) {
      this.CustomSelectedRow = row;
      switch (this.selectTab) {
        case 'tab1':
          this.DoQueryTopTab1(row.id);
          break;
        case 'tab2':
          this.DoQueryTopTab2(row.id);
          break;
        case 'tab3':
          this.DoQueryTopTab3(row.id);
          break;
      }
    },
    handleTab1TopGridCellClick({ row }) {
      this.ProjectSelectdRow = row;
      switch (this.childSelectTab) {
        case 'childtab1':
          this.DoQueryTab1ChildTab1(row.id);
          break;
      }
    },
    handleTopTabClick() {
      switch (this.selectTab) {
        case 'tab1':
          this.DoQueryTopTab1(this.CustomSelectedRow.id);
          break;
        case 'tab2':
          this.DoQueryTopTab2(this.CustomSelectedRow.id);
          break;
        case 'tab3':
          this.DoQueryTopTab3(this.CustomSelectedRow.id);
          break;
      }
    },
    handleTab1ChildTabClick() {
      switch (this.childSelectTab) {
        case 'childtab1':
          this.DoQueryTab1ChildTab1(this.ProjectSelectdRow.id);
          break;
        case 'childtab2':
          this.DoQueryTab1ChildTab2(this.ProjectSelectdRow.id);
          break
        case 'childtab3':
          this.DoQueryTab1ChildTab3(this.ProjectSelectdRow.id);
          break
        case 'childtab4':
          this.DoQueryTab1ChildTab4(this.ProjectSelectdRow.id);
          break
      }
    },
    DoQuery(e) {
      let request = {
        isPaging: false,
        pageSize: 1,
        pageIndex: 1,
        queryConditions: e,
        orderByConditions: []
      }
      CURDHelper.Query(request, this.BaseApiUrl)
        .then(res => {
          this.LeftGridOptions.data = res.data;
          this.editRow = undefined;
        }).catch(err => {
          VxeUI.modal.message({ content: `${err}`, status: 'error', duration: this.duration })
        })
    },
    DoQueryTopTab1(id) {
      let request = {
        isPaging: false,
        pageSize: 1,
        pageIndex: 1,
        queryConditions: [{ column: 'khid', condition: '0', content: id }],
        orderByConditions: [{ column: 'createtime', condition: 'desc' }]
      }
      CURDHelper.Query(request, this.XmxxApiUrl)
        .then(res => {
          this.Tab1TopGridOptions.data = res.data;
          this.Tab1ChildTab1GridOptions.data = [];
          this.Tab1ChildTab2GridOptions.data = [];
          this.Tab1ChildTab3GridOptions.data = [];
          this.Tab1ChildTab4GridOptions.data = [];
        }).catch(err => {
          VxeUI.modal.message({ content: `${err}`, status: 'error', duration: this.duration })
        })
    },
    DoQueryTopTab2(id) {
      let request = {
        isPaging: false,
        pageSize: 1,
        pageIndex: 1,
        queryConditions: [{ column: 'khid', condition: '0', content: id }],
        orderByConditions: [{ column: 'gjsj', condition: 'desc' }]
      }
      CURDHelper.Query(request, this.KhgdglApiUrl)
        .then(res => {
          this.Tab2TopGridOptions.data = res.data;
        }).catch(err => {
          VxeUI.modal.message({ content: `${err}`, status: 'error', duration: this.duration })
        })
    },
    DoQueryTopTab3(id) {
      let request = {
        isPaging: false,
        pageSize: 1,
        pageIndex: 1,
        queryConditions: [{ column: 'khid', condition: '0', content: id }],
        orderByConditions: []
      }
      CURDHelper.Query(request, this.KhgltxApiUrl)
        .then(res => {
          this.Tab3TopGridOptions.data = res.data;
        }).catch(err => {
          VxeUI.modal.message({ content: `${err}`, status: 'error', duration: this.duration })
        })
    },
    DoQueryTab1ChildTab1(id) {
      let request = {
        isPaging: false,
        pageSize: 1,
        pageIndex: 1,
        queryConditions: [{ column: 't.xmid', condition: '0', content: id }],
        orderByConditions: []
      }
      CURDHelper.Query(request, this.XmxxpcApiUrl)
        .then(res => {
          this.Tab1ChildTab1GridOptions.data = res.data;
        }).catch(err => {
          VxeUI.modal.message({ content: `${err}`, status: 'error', duration: this.duration })
        })
    },
    DoQueryTab1ChildTab2(id) {
      let request = {
        isPaging: false,
        pageSize: 1,
        pageIndex: 1,
        queryConditions: [{ column: 'xmid', condition: '0', content: id }],
        orderByConditions: []
      }
      CURDHelper.Query(request, this.XmxxlcApiUrl)
        .then(res => {
          this.Tab1ChildTab2GridOptions.data = res.data;
        }).catch(err => {
          VxeUI.modal.message({ content: `${err}`, status: 'error', duration: this.duration })
        })
    },
    DoQueryTab1ChildTab3(id) {
      let request = {
        isPaging: false,
        pageSize: 1,
        pageIndex: 1,
        queryConditions: [{ column: 'xmid', condition: '0', content: id }],
        orderByConditions: []
      }
      CURDHelper.Query(request, this.XmxxskApiUrl)
        .then(res => {
          this.Tab1ChildTab3GridOptions.data = res.data;
        }).catch(err => {
          VxeUI.modal.message({ content: `${err}`, status: 'error', duration: this.duration })
        })
    },
    DoQueryTab1ChildTab4(id) {
      let request = {
        isPaging: false,
        pageSize: 1,
        pageIndex: 1,
        queryConditions: [{ column: 'xmid', condition: '0', content: id }],
        orderByConditions: []
      }
      CURDHelper.Query(request, this.XmxxkpApiUrl)
        .then(res => {
          this.Tab1ChildTab4GridOptions.data = res.data;
        }).catch(err => {
          VxeUI.modal.message({ content: `${err}`, status: 'error', duration: this.duration })
        })
    },
  }
}
